module.exports   B
last analyzed

Complexity

Conditions 1
Paths 3

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1.0005

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 25
ccs 11
cts 12
cp 0.9167
crap 1.0005
rs 8.8571

1 Function

Rating   Name   Duplication   Size   Complexity  
A 0 23 3
1 1
var jwt = require('jsonwebtoken');
2
3 1
module.exports = function(secret) {
4 1
    return function(req, res, next) {
5
        let token;
6 3
        if (req.headers.authorization) {
7
            token = req.headers['authorization'].split(' ')[1];
8
        } else {
9 3
            token = req.body.token || req.query.token || req.headers['x-access-token'];
10
        }
11 3
        if (token) {
12 2
            jwt.verify(token, secret, function(err, decoded) {
13 2
                if (err) {
14 1
                    return res.status(403).send({ success: false, message: 'Failed to authenticate token.' });
15
                } else {
16 1
                    req.decoded = decoded;
17 1
                    next();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
18
                }
19
            });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
20
        } else {
21 1
            return res.status(403).send({
22
                success: false,
23
                message: 'No token provided.'
24
            });
25
        }
26
    }
27
}
28